/**************************************************************************************
*
*	Copyright (C) 2010 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	Matrix4x4.h
*
*	Description -	4x4 matrix class.
*
*	Comments	-	
*
*	Modification History:
*			Name			   Date					Description
*			MrCodeSushi	-	02/24/2010		-	File creation
**************************************************************************************/
#ifndef _PSX_PLANE_H_
#define _PSX_PLANE_H_

#include "PulseSTD.h"
#include "Math.h"
#include "Vector3.h"

namespace Pulse
{

	class Plane
	{
	public:

		Plane( void );

		Plane( FLOAT a, FLOAT b, FLOAT c, FLOAT d );

		void Normalize( void );

		FLOAT DistanceToPoint( const Vector3 *pPoint ) const;


	public:

		// Storage is (a, b, c ,-d).
		union
		{
			FLOAT _array[4];

			struct
			{
				FLOAT a;
				FLOAT b;
				FLOAT c;
				FLOAT d;
			};
		};
	};

	PSX_INLINE Plane::Plane( void )
	{
		_array[0] = 0.0f;
		_array[1] = 0.0f;
		_array[2] = 0.0f;
		_array[3] = 0.0f;
	}

	PSX_INLINE Plane::Plane( FLOAT a, FLOAT b, FLOAT c, FLOAT d )
	{
		_array[0] = a;
		_array[1] = b;
		_array[2] = c;
		_array[3] = d;
	}

	PSX_INLINE void Plane::Normalize( void )
	{
		FLOAT magnitude = Math::Sqrtf( a*a + b*b + c*c );
		FLOAT inverseMag = 1.0f/ magnitude;

		_array[0] *= inverseMag;
		_array[1] *= inverseMag;
		_array[2] *= inverseMag;
		_array[3] *= inverseMag;
	}

	PSX_INLINE FLOAT Plane::DistanceToPoint( const Vector3 *pPoint ) const
	{
		return ( a * pPoint->x + 
			b * pPoint->y +
			c * pPoint->z +
			d );
	}

}

#endif /* _PSX_PLANE_H_ */
